"""
@Time ： 2021/10/18 17:53
@Auth ： ChenZhangkun
"""


class Gun:
    """
    枪类
    """

    def __init__(self, model):
        # 1枪的型号
        self.model = model
        self.bullet_count = 0

    def add_bullet(self, count):
        self.bullet_count += count

    def shoot(self):
        # 判断子弹数量
        if self.bullet_count <= 0:
            print("%s没有子弹，不能发射" % self.model)
            return
        self.bullet_count -= 1
        print("[%s] 突突突 [%d]" % (self.model, self.bullet_count))

    def __str__(self):
        return self.model


ak17 = Gun("AK47")
ak17.add_bullet(50)
ak17.shoot()


class Soldier:
    def __init__(self, name):
        self.name = name
        # 枪-新兵没有枪
        self.gun = None

    def fire(self):
        if self.gun is None:
            print("士兵没枪")
            return
        print("冲啊、、、[%s]" % self.name)

        # zhuang子弹
        if self.gun.bullet_count <= 0:
            self.gun.add_bullet(50)
        # 发射
        self.gun.shoot()


czk = Soldier("czk")
# 加枪
czk.gun = ak17
print(czk.gun)
czk.fire()
